package com.wwwarehouse.usercenter.fragment.business_relationship;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.Animation;

import com.wwwarehouse.common.activity.base.BaseFragment;
import com.wwwarehouse.common.custom_widget.SpaceItemDecoration;
import com.wwwarehouse.usercenter.R;
import com.wwwarehouse.usercenter.adapter.BRCFCDSelectSalesmanAdapter;
import com.wwwarehouse.usercenter.adapter.BRCFDSelectSalesmanAdapter;
import com.wwwarehouse.usercenter.bean.business_relationship.GetRelationSalesmansBean;

import java.util.ArrayList;


/**
 * 权限管理 -> 选择你要分配的人
 * Created by ShineF on 2017/9/25 0025.
 */

public class BRCFCDSelectSalesmanListFragment extends BaseFragment{

	private RecyclerView mRvContent;
	private boolean isMeasured = false;
	private BRCFCDSelectSalesmanAdapter mAdapter;
	private ArrayList<GetRelationSalesmansBean> mDataList;

	@Override
	public void onCreate(@Nullable Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		Bundle bundle = getArguments();
		if (bundle != null) {
			mDataList = bundle.getParcelableArrayList("perPageList");
		}
	}

	@Nullable
	@Override
	public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
		return inflater.inflate(R.layout.fragment_select_distribution_pager_content_permission, container, false);
	}

	@Override
	public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
		super.onViewCreated(view, savedInstanceState);
		mRvContent = $(R.id.rv_content);
		mRvContent.addItemDecoration(new SpaceItemDecoration(10, 10));
		mRvContent.setLayoutManager(new GridLayoutManager(mActivity, 3));
		measureHeight();
	}

	public void measureHeight() {
		ViewTreeObserver observer = mRvContent.getViewTreeObserver();
		observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
			public boolean onPreDraw() {
				if (!isMeasured) {
					setHeight(mRvContent.getMeasuredHeight());
				}
				return true;
			}
		});
	}


	@Override
	public void setTitle() {
	}

	@Override
	public void requestDatas() {

	}

	@Override
	public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
		return null;
	}

	public void setHeight(int height) {
		isMeasured = true;
		if (mAdapter == null && isAdded()) {
			mAdapter = new BRCFCDSelectSalesmanAdapter(mActivity, mDataList, height);
			mRvContent.setAdapter(mAdapter);
		}
	}

}
